Skip to content

Experiment: optimized representation for nat constants (a zarith Z.t values)#21729

Draft
SkySkimmer wants to merge 46 commits intorocq-prover:masterfrom
SkySkimmer:bignat
Draft

Experiment: optimized representation for nat constants (a zarith Z.t values)#21729
SkySkimmer wants to merge 46 commits intorocq-prover:masterfrom
SkySkimmer:bignat

Conversation

@SkySkimmer
Copy link
Contributor

The current state has some random TODOs and term matching (notation printing, ltac matching) is probably janky but is enough to have a look.

Prelude nat does not use the optimization (so CI should say nothing interesting), see new test file bignat for actual use of the optimization.

The optimization is similar to what agda https://agda.readthedocs.io/en/latest/language/built-ins.html#natural-numbers and lean https://lean-lang.org/doc/reference/latest/Basic-Types/Natural-Numbers/ have: closed nat values ("nat constants") can be represented by Nat of Z.t.

The cbv machine has optimized implementations for +/* on nat constants (the one for tail_mul is necessary to get large literals to work).

The VM produces values using the optimized representation but has no special handling for operators.

cclosure/lazy/cclosure-based conversion can handle inputs which contain the optimized representation but do not build larger values using it, ie 1 + 1 where 1 is optimized reduces to S 1 (which converts correctly to 2).
TBH I'm not sure how to do otherwise in a lazy/call by name setting, if we see 1 + e for some arbitrary expression e we should not reduce e (at least in weak head mode).

native_compute, cbn and reductionops do failwith "TODO" on optimized constants.
I think tacred treats optimized constants as opaque values but who knows what this code even is.

@coqbot-app coqbot-app bot added the needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. label Mar 6, 2026
@ppedrot
Copy link
Member

ppedrot commented Mar 6, 2026

It's not because all your friends are jumping off a cliff that you should do it...

@SkySkimmer SkySkimmer force-pushed the bignat branch 3 times, most recently from 2cc50b3 to a76d28b Compare March 9, 2026 16:56
SkySkimmer added a commit to SkySkimmer/Coq-Equations that referenced this pull request Mar 11, 2026
SkySkimmer added a commit to SkySkimmer/MetaRocq that referenced this pull request Mar 11, 2026
@SkySkimmer SkySkimmer added the request: full CI Use this label when you want your next push to trigger a full CI. label Mar 11, 2026
@coqbot-app coqbot-app bot removed the request: full CI Use this label when you want your next push to trigger a full CI. label Mar 11, 2026
@SkySkimmer
Copy link
Contributor Author

@coqbot bench

@SkySkimmer SkySkimmer added the request: full CI Use this label when you want your next push to trigger a full CI. label Mar 11, 2026
@coqbot-app coqbot-app bot removed the request: full CI Use this label when you want your next push to trigger a full CI. label Mar 11, 2026
@SkySkimmer
Copy link
Contributor Author

@coqbot bench

@SkySkimmer SkySkimmer added the request: full CI Use this label when you want your next push to trigger a full CI. label Mar 11, 2026
@coqbot-app coqbot-app bot removed the request: full CI Use this label when you want your next push to trigger a full CI. label Mar 11, 2026
@SkySkimmer
Copy link
Contributor Author

@coqbot bench

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants